# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=netripper
pkgver=84.c763bd0
pkgrel=1
pkgdesc='Smart traffic sniffing for penetration testers.'
groups=('blackarch' 'blackarch-windows')
arch=('any')
url='https://github.com/NytroRST/NetRipper'
license=('GPL3')
makedepends=('git' 'curl' 'sed')
optdepends=('metasploit')
source=("$pkgname::git+https://github.com/NytroRST/NetRipper.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

package() {
  jobId=$(curl https://ci.appveyor.com/api/projects/NytroRST/netripper |
    sed 's|.*jobId":"\([^"]*\)".*|\1|gi')
  baseUrl="https://ci.appveyor.com/api/buildjobs/${jobId}/artifacts/"
  msfDir="$pkgdir/opt/metasploit/modules/post/windows/gather/$pkgname/"

  install -dm 755 "$msfDir"
  install -dm 755 "$pkgdir/usr/share/windows/$pkgname"
  install -dm 755 "$pkgdir/opt/$pkgname/windows/archive"

  curl -L -o './DLL.x86.dll' "${baseUrl}x86%2FDLL.x86.dll"
  curl -L -o './DLL.x64.dll' "${baseUrl}x64%2FDLL.x64.dll"
  curl -L -o './NetRipper.x86.exe' "${baseUrl}x86%2FNetRipper.x86.exe"
  curl -L -o './NetRipper.x64.exe' "${baseUrl}x64%2FNetRipper.x64.exe"

  cp ./DLL.x86.dll "$pkgdir/opt/$pkgname/windows/archive/"
  cp ./DLL.x64.dll "$pkgdir/opt/$pkgname/windows/archive/"
  cp ./NetRipper.x86.exe \
    "$pkgdir/usr/share/windows/$pkgname/NetRipper.x86.exe"
  cp ./NetRipper.x64.exe \
    "$pkgdir/usr/share/windows/$pkgname/NetRipper.x64.exe"
  cp "$pkgname/PowerShell/Invoke-NetRipper.ps1" \
    "$pkgdir/usr/share/windows/$pkgname/"

  # Metasploit
  cp "$pkgname/Metasploit/netripper.rb" $msfDir
  cp ./DLL.x64.dll $msfDir
  cp ./DLL.x86.dll $msfDir

  install -Dm 644 "$pkgname/LICENSE.TXT" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

